﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gma.QrCodeNet.Encoding;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            if (args.Length != 0)//检测命令行参数是否为空
            {
                foreach (string x in args)//对args中每个string进行检测
                {
                    if (x.Length <= 30)//检测命令行参数长度是否小于30
                    {
                        QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
                        QrCode qrCode = qrEncoder.Encode(x);
                        for (int j = 0; j < qrCode.Matrix.Width; j++)//绘制qrcode
                        {
                            for (int i = 0; i < qrCode.Matrix.Width; i++)
                            {
                                char charToPrint = qrCode.Matrix[i, j] ? '█' : '　';//利用双重嵌套绘制qrcode
                                Console.Write(charToPrint);//利用双重嵌套绘制qrcode
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }


            else {
                 Console.Write(@"Type some text to QR code: ");
                 string sampleText = Console.ReadLine();//如不使用命令行参数则另外输入
                while (sampleText.Length == 0)//判断长度是否等于0，是则重新输入
                {
                    Console.WriteLine("Please enter legal content:");//询问是否重新输入
                    sampleText = Console.ReadLine();
                }
                QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
                 QrCode qrCode = qrEncoder.Encode(sampleText);
                 for (int j = 0; j < qrCode.Matrix.Width; j++)
                 {
                     for (int i = 0; i < qrCode.Matrix.Width; i++)
                     {
                         char charToPrint = qrCode.Matrix[i, j] ? '█' : '　';
                         Console.Write(charToPrint);
                     }
                     Console.WriteLine();
                 }
             }

             Console.WriteLine(@"Press any key to quit.");
             Console.ReadKey();
            Form1 f = new Form1();//弹出ui界面
            f.ShowDialog();//弹出ui界面
        }
    }
}
